/*
 * GZombieMovStrategy.cpp
 *
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses 
 */

#include "GZombieMovStrategy.h"
#include "Bomberman.h"
#include "ModelConstants.h"
#include <cstdlib>

void GZombieMovStrategy::resolveMoveDirection(Map& map) {
    // Only the first time
    if (zombie->getDirection() == NO_DIRECTION) {
        zombie->determineMovementDirection(map);
    }
    // If the movement range has been reached
    int dist_spawn = getDistanceToSpawn();
    if (std::abs(dist_spawn) >= zombie->getRange()) {
        zombie->turnAround();
    } else {
        // If a bomberman is in sight, chase it
        int chased_bomberman_direction = zombie->scoutForBomberman(map);
        if (chased_bomberman_direction != NO_DIRECTION) {
            zombie->setDirection(chased_bomberman_direction);
        }
    }
}

void GZombieMovStrategy::resolveInvalidMove(Map& map) {
    // Given the movemente restrictions, it can only turn around
    zombie->turnAround();
}

int GZombieMovStrategy::getDistanceToSpawn() {
    if ((zombie->getDirection() == UP) || (zombie->getDirection() == DOWN)) {
        return zombie->verticalDistanceToSpawn();
    }
    return zombie->horizontalDistanceToSpawn();
}
